import json

class Hicharts:
    def __init__(self):
        self.Data = {}
        self.Data['xAxis'] = {'plotLines':[{'value': 0, 'width': 1, 'color':'#808080'}]}
        self.Data['xAxis']['categories'] = []
        self.Data['yAxis'] = {}
        self.Data['series'] = []
        self.Data['legend'] = {
            'layout': 'vertical',
            'align': 'right',
            'verticalAlign': 'middle',
            'borderWidth': 0
            }  

    def GetJsonContext(self, context = {}, name = 'hicharts'):
        return dict ({name:json.dumps(self.Data)}, **context)
    
    def SetTitle(self, title):
        self.Data['title'] = {'text': title}

    def SetAxisTitle(self, axis, title):
        self.Data[axis]['title'] = {'text': title}

    def SetXAxisTitle(self, title):
        self.SetAxisTitle('xAxis', title) 

    def SetYAxisTitle(self, title):
        self.SetAxisTitle('yAxis', title)     
    
    
    def SetTooltipValueSuffix(self, valueSuffix):
        self.Data['tooltip'] = {'valueSuffix':valueSuffix}
        
    def AddSeries(self, name, data):
        self.Data['series'].append({'name':name, 'data':data})

    def SetXAxisCategories(self, c):
        self.Data['xAxis']['categories'] = c


def Test():
    hc = Hicharts()
    hc.SetTitle('Test title')
    hc.SetXAxisTitle('X')
    hc.SetYAxisTitle('Y')
    hc.SetXAxisCategories(['00:00', '00:05', '00:10', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
    hc.AddSeries('series1', [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8])
    #hc.SetTooltipValueSuffix('val')
    return hc.GetJsonContext() 
